<?php
namespace app\admin\controller;

use think\Db;
use think\Log;
use Qiniu\Auth as QnAuth;
use Qiniu\Storage\BucketManager;
use Qiniu\Storage\UploadManager;
use app\home\model\CreditRecord;
use app\admin\model\Config;

class Connection extends Base{

      public function index(){
        if(request()->isAjax()){
            $ids = params_array('ids');
            if(!check_array($ids)){
                message('请选择要删除的内容','','error');
            }
           $status=db('connection')->where(['connection_id'=>['in',$ids]])->delete();
            if(!$status){
                message('删除失败','','error');
            }
            message("删除成功",'reload','success');
        }
        $where=[];

        $params = request()->param();
        if(!empty($params['uid'])){
            $where['uid'] =$params['uid'];
        }

        $total = \app\admin\model\Chat::getCount($where);
      //  $list = \app\admin\model\Chat::getPagination($where, 15, $total, "id DESC");
        $list=db('connection')->alias('a')->join('member b','a.uid= b.uid')->where($where)->order('connection_id desc')->paginate(25);

        
        $pager = $list->render();
        return $this->fetch(__FUNCTION__, [
            'list' => $list,
            'pager' => $pager,
            'total' => $total
        ]);
    }
	

    //直接审核通过
    public function pass(){
    	$res = db('connection')->where('connection_id',input('id'))->setField('checked',1);
    	if($res){
    		//扣除余额
    		message("成功",'','success');
    	}else{
    		message("失败",'','error');
    	}
    }
    //直接审核不通过
    public function nopass(){
    
    	$data['checked'] = 2;
    	$res = db('connection')->where('connection_id',input('id'))->update($data);
    
    	if($res){
    		//退回费用
					$info=db('connection')->where('connection_id',input('id'))->find();
    					
					//费用
					$config = Config::getInfo();
		            $fee = 0;
		            $type=$info['type'];
		            if(!empty($config['setting']['rm_fee_'.$type])){
		                $fee = floatval(trim($config['setting']['rm_fee_'.$type]));
		            }
					
	            	//扣除费用
	            	 //记录提现操作
	            	 $result=db('member')->where('uid',$info['uid'])->setInc('credit2',$fee);
	            	 if($result){
	            	 	
			            $status2 = CreditRecord::addInfo([
			                'uid' => $info['uid'],
			                'type' => 'credit2',
			                'num' => $fee,
			                'title' => '发布人脉信息审核失败',
			                'remark' => "发布人脉信息审核失败，返回{$fee}余额。",
			                'create_time' => TIMESTAMP
			            ]);
			            if(!$status2){
			                Db::rollback();
			                message('操作失败：-2','','error');
			            }
	            	 }else{
	            	 		Db::rollback();
			                message('缺少参数：-2','','error');
	            	 }    		

    		
    		message("操作成功",'','success');
    	}else{
    		message("操作失败",'','error');
    	}
    }
	
	
	
	
	
}